<?php include 'inc/student_head.php';?>





<script language="javascript">
    layui.use(function () {
        var form = layui.form
            , upload = layui.upload
            , table = layui.table
            , $ = layui.$;




$("#menu_task").addClass('layui-this'); //设置导航当前选中项的样式



table.render({
        elem:'#task'
        ,id:'task'
        ,url:'task'
        ,method:'post'
        ,height:380
        ,cols:[[
            {type:'numbers',title:'序号',width:80},
            {field:'name',title:'课程名称',event:'downTask',style:'cursor: pointer;'},
            {toolbar:'#downTask',title:'下载课程',width:100,align:'center'},
            {toolbar:'#a',title:'上传作业',width:140,align:'center'},
            // {toolbar:'#b',title:'下载作业',width:140,align:'center'},

        ]]
        ,page:false
        ,where:{
            cat:$('#cat').val(),
        }

    });

// 所有课程 弹出层
layer.open({
    type: 1,
    title: '<div class="openTitle"><h2>所 有 课 程</h2></div>',
    anim: 0,
    scrollbar: false,
    area: ['750px','570px'],
    shade: false,
    content: $('.openDiv'),
    offset: '120px',
    closeBtn: 2,
    cancel: function(index, layero){
        window.location.href="/student/index";
    }
});


form.on('select',function(){
    table.reload('task',{where:{cat:$('#cat').val()}});
})

var upI=upload.render({
    elem: '#upTask'
    , url: 'upZY'
    , accept: 'file' //普通文件
    , exts: 'zip|rar|7z' //只允许上传压缩文件
    , acceptMime: '.zip,.rar,.7z'//打开文件框筛选文件类型
    , size: 20 * 1024
    , done: function (res) {
        if (res.code === 0) {
            layer.alert('上传成功', {icon: 6}, function () {
                location.reload();
            });
        }else{
            layer.alert(res.msg);
        }
    }
});


table.on('tool',function(obj){
    let event=obj.event;
    if(event=='up'){        //上传课程
        upI.reload({
            data:{task:obj.data.id}
        });
        $('#upTask').click();
    }
    //下载课程
    if(event=='downTask'){
        location.href='downTask?taskID='+ obj.data.id;
    }
    //下载自己的作业
    if(event=='downZY'){
        location.href='downZY?taskID='+ obj.data.id;
    }

})



});//end
</script>

<?php include 'inc/student_foot.php';?>

<script type="text/html" id='downTask'>
    <button class='layui-btn layui-btn-xs' lay-event='downTask'> 下载课程 </button>
</script>

<script type="text/html" id='a'>
    <button class='layui-btn layui-btn-xs layui-btn-normal' lay-event='up'> 上传该课作业 </button>
</script>

<!-- <script type="text/html" id='b'>
    <button class='layui-btn layui-btn-xs b1' lay-event='downZY'> 下载我的作业 </button>
</script> -->

<!-- 上传组件绑定 -->
<a id='upTask'></a>



<div class='openDiv' style="text-align: left;">

    <div class="layui-row layui-form">
        <br>
        <div style="text-align: center">
            <div style="display: inline-block;">
                <label class='selectLabel' style="">
                <b class="y-blue">请选择课程分类：</b>
                </label>
            </div>
            <div style="display: inline-block;text-align: left">
                <select name="cat" id='cat'>
                <?php
                    foreach ($this->cats as $key => $v) {
                        echo "<option value=$v[id]>$v[name]</option>";
                    }
                ?>
                </select>
            </div>
        </div>

        <div style="background: #fff;padding:10px 20px;">
            <table id='task' layui-filter='task'></table>
        </div>
    </div>

</div>